package com.chis.jmdatatimer.comm;

import com.chis.jm.pojo.Child;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import redis.clients.jedis.ShardedJedis;

/**
 * @Description 查询儿童基本信息
 * @Company zwx
 * @author CZJ
 * @version 2016/6/24
 */
public class RedisFindChildTx implements TransactionJedis {
	/**日志*/
	private static Logger log = LogManager.getLogger(RedisFindChildTx.class);
	/** 儿童编码 */
	private String childCode;
	/** 儿童基本信息 */
	private Child child;

	public RedisFindChildTx(String childCode) {
		this.childCode = childCode;
	}

	@Override
	public void run(ShardedJedis jedis) throws Exception {
		try {
			jedis.select(0);
			// 取出客户端不能修改的字段, 设置入child
			byte[] bytes = jedis.get(childCode.getBytes());
			if (bytes != null && bytes.length > 0) {
				child = (Child) JedisSerializeUtil.unserialize(bytes);
			}
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw new Exception(e.getMessage());
		}
	}

	public Child getChild() {
		return child;
	}

}
